﻿using System;
using NguyenHoa.Domains;
using NguyenHoa.Services;
using NguyenHoa.Web.App_Code;

namespace NguyenHoa.Web.Pages
{
  public partial class ContactPage : BasePage
  {
    #region Properties
    private string CPType
    {
      get
      {
        string type = Request.QueryString["cpType"];
        return string.IsNullOrEmpty(type) ? ContactPageType.OnlineContact : type;
      }
    }

    internal override string PageTitle
    {
      get
      {
        string title;
        switch (CPType)
        {
          case ContactPageType.OnlineSale:
            title = Resources.Strings.OnlineSale;
            break;
          case ContactPageType.SendOpinion:
            string type = Request.QueryString["type"];
            switch (type)
            {
              case CustomerContactType.Contact:
                title = Resources.Strings.OnlineContact;
                break;
              default:
                title = Resources.Strings.Comment;
                break;
            }
            break;
          default:
            title = Resources.Strings.OnlineSupport;
            break;
        }
        return title;
      }
    }
    #endregion

    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack && !IsCallback)
      {
        LoadInfo();
      }
    }
    #endregion

    #region Methods
    private void LoadInfo()
    {
      ContactInfo contactInfo;
      TList<ContactInfo> cList = new ContactInfoService().GetByTypeAndLanguage(ContactType.ContactInfo, CurrentLanguage.Id, true);
      if (cList.Count > 0)
      {
        contactInfo = cList[0];
        ltrContactInfo.Text = contactInfo.Value;
      }

      TList<ContactInfo> mapList = new ContactInfoService().GetByTypeAndLanguage(ContactType.ViewMap, CurrentLanguage.Id, true);
      if (mapList.Count > 0)
      {
        aViewMap.Attributes["onclick"] = "gotoWebsite('" + mapList[0].Value + "')";
      }
    }
    #endregion
  }
}
